<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>todoList</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        #todo {
            width: 100%;
            height: 700px;
        }
        .head {
            width: 100%;
            height: 150px;
            background-color: rgb(141, 133, 141);
        }
        .container-head {
            width: 100%;
            margin: auto;
            display: flex;
            align-items: center;
        }
        .container-head>input {
            width: 60%;
            height: 40px;
            margin-left: 30px;
            outline: none;
            cursor: pointer;
            text-indent: 1em;
        }
        .container-head>button {
            width: 30%;
            height: 40px;
            cursor: pointer;
        }
        .list {
            width: 100%;
            height: 60px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: rgb(225, 225, 225);
            margin-bottom: 1px;
            padding: 0;
        }
        .yes {
            width: 40px;
            height: 60px;
            /* background-color: #b99a9a; */
            /* background-image: url(./yes.png);
            background-size: 50px 50px; */
            display: none;
        }
        .dele {
            width: 30px;
            height: 30px;
            /* background-image: url(./no.png); */
            /* position: fixed; */
            right: 0;
        }
        img {
            width: 30px;
            height: 30px;
            margin: 10px;
        }
        li {
            list-style: none;
        }
        .line{
            text-decoration: line-through;
        }

    </style>
    <script src="../day6jquery/jquery3.5.min.js"></script>
</head>

<body>
    <div id="todo">
        <div class="head">
            <h1 style="text-align: center; padding-top: 20px;">todoList</h1>
            <div class="container-head">
                <input type="text" placeholder="请输入需要添加的任务" />
                <button>add</button>
            </div>
        </div>
        <div class="todo-body">
            <ul class="title"></ul>
        </div>
    </div>
    <script>;
        let ipt = document.querySelector('input');
        let add = document.querySelector('button');
        let tit = document.querySelector('.title');
        let list = document.querySelector('.list');
        let li = document.querySelectorAll('li');
        ipt.onkeydown = function (e) {
            if (e.keyCode === 13) {
                checkIpt()
            }
        }
        add.onclick = function () {
            checkIpt()
        }
        function checkIpt() {
            if (ipt.value === '') {
                alert('请先输入任务')
            }else{
                let li = document.createElement('li');
                li.className = 'list'
                li.innerHTML = "<img class='yes' src='./yes.png'>" + '<p>'+ipt.value +'</p>'+ "<img class='dele' src='./no.png'></img>";
                tit.appendChild(li);
                localStorage.setItem( 'lists',JSON.stringify(ipt.value))
                ipt.value = '';
                let yes = $('.yes')
                yes.bind('click',function(){
                    let p = $('p').text();
                    // debugger
                    if(this.parentNode.style.textDecoration !== 'line-through'){
                        this.parentNode.style.textDecoration ='line-through';
                        let lt = this.parentNode.style.textDecoration;
                        console.log(lt);
                    }else{
                        this.parentNode.style.textDecoration = 'blink'
                    }
                })
                let de = $('.dele')
                de.bind('click',function(){
                   for(var i = 0; i<de.length; i++){
                       let de = this.parentElement
                        de.remove()
                   }
                })
                li.onmouseover = function() {
                    let sum = this.firstChild.style.display;
                    if(sum == 'none'){
                        this.firstChild.style.display = 'block'
                    this.style.backgroundColor = 'rgb(166 162 162)'
                    }
                    
                    
                }
                li.onmouseout = function() {
                    this.firstChild.style.display = 'none'
                    this.style.backgroundColor = 'rgb(225, 225, 225)'
                } 
            }
            return
        }
        // let li =tit.document.querySelectorAll('li');
        // console.log(li);
        // for(var i = 0; i < tit.children;i++){
        //     console.log(tit);
        // }
        
    </script>
</body>

</html>